#include "xlcd.h"
#include "delay.h"

/*******************************************************************
Function Name:            WriteDataXLCD
Description:              This function writes a data byte into the 
                          DDRam/CGRam of the LCD controller.The user
                          must first check the busy  status of the 
                          LCD controller  by calling the BusyXLCD()
                          function.The data written can go to the 
                          DDRam or CGRam depending on the previous
                          SetXXRamAddr( char) that was  called.
Input parameters:         char data
Return value:             void
********************************************************************/
void WriteDataXLCD( char data)
{
    RS_PIN = 1;  /* select Data Reg */
    RW_PIN = 0;  /* enable write */

    /* configure the common data pins as output */
    TRIS_DATA_PIN_7 = 0;
    TRIS_DATA_PIN_6 = 0;
    TRIS_DATA_PIN_5 = 0;
    TRIS_DATA_PIN_4 = 0;

    DATA_PIN_7 = (unsigned int)((data & 0x80)>>7);
    DATA_PIN_6 = (unsigned int)((data & 0x40)>>6);
    DATA_PIN_5 = (unsigned int)((data & 0x20)>>5);
    DATA_PIN_4 = (unsigned int)((data & 0x10)>>4);


    E_PIN = 1; /* Clock nibble into LCD */
    DelayEPulseWidthHigh();
    E_PIN = 0;
    DelayEPulseWidthLow();

    DATA_PIN_7 = (unsigned int)((data & 0x08)>>3);
    DATA_PIN_6 = (unsigned int)((data & 0x04)>>2);
    DATA_PIN_5 = (unsigned int)((data & 0x02)>>1);
    DATA_PIN_4 = (unsigned int)((data & 0x01)>>0);


    E_PIN = 1;			 /* Clock nibble into LCD */
    DelayEPulseWidthHigh();
    E_PIN = 0;
    DelayEPulseWidthLow();

    /*configure all pins to input mode*/
    TRIS_DATA_PIN_7 = 1;
    TRIS_DATA_PIN_6 = 1;
    TRIS_DATA_PIN_5 = 1;
    TRIS_DATA_PIN_4 = 1;


}  /* end of function */
